package me.hushuang.webb.back.service;

import me.hushuang.webb.back.mapper.UrlFilterMapper;
import me.hushuang.webb.back.model.UrlFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * 
 */
@Service
public class UrlFilterService{

    @Autowired
    private UrlFilterMapper urlFilterMapper;

    @Autowired
    private ShiroFilerChainManager shiroFilerChainManager;

    public UrlFilter createUrlFilter(UrlFilter urlFilter) {
        urlFilterMapper.createUrlFilter(urlFilter);
        initFilterChain();
        return urlFilter;
    }



    public UrlFilter updateUrlFilter(UrlFilter urlFilter) {
        urlFilterMapper.updateUrlFilter(urlFilter);
        initFilterChain();
        return urlFilter;
    }

    public void deleteUrlFilter(Long urlFilterId) {
        urlFilterMapper.deleteUrlFilter(urlFilterId);
        initFilterChain();
    }

    public UrlFilter findOne(Long urlFilterId) {
        return urlFilterMapper.findOne(urlFilterId);
    }

    public List<UrlFilter> findAll() {
        return urlFilterMapper.findAll();
    }

    @PostConstruct
    public void initFilterChain() {
        shiroFilerChainManager.initFilterChains(findAll());
    }

}
